package web;

import java.io.IOException;
import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import com.DBCon;
import com.MD5;

/**
 * Servlet implementation class ServletDeleteDepNum
 */
@WebServlet({ "/ServletDeleteDepNum", "/Manager/DelDep" })
public class ServletDeleteDepNum extends HttpServlet {
	private static final long serialVersionUID = 1L;

	/**
	 * @see HttpServlet#doGet(HttpServletRequest request, HttpServletResponse response)
	 */
	protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		// TODO Auto-generated method stub
	    request.setCharacterEncoding("utf-8");
	    String UserNum = request.getParameter("usernum");
	    String pg = request.getParameter("pg");
	    String sql1 = "";
	    String sql2 = "";
	    //构造写入数据库的SQL
	   
	     //删除用户表的账号
	     sql1 = "delete from user where UserNum='"+UserNum+"'";  
	     System.out.println("UserDelete sql1=" + sql1);
	     //删除学院联系人表的账号
	     sql2="delete from department where DepNum='"+UserNum+"'";
	    //连接数据库
			try {
				int ret1,ret2;
				ret1 = new DBCon().query(sql1);
				ret2 = new DBCon().query(sql2);
		        System.out.println("ret1=" + ret1);
		        System.out.println("ret2=" + ret2);
			} catch (Exception e) {
				// TODO Auto-generated catch block
				e.printStackTrace();
			}
	    //返回页面
		request.setAttribute("p",pg);
		System.out.println("Sendback pg="+pg);
		//重定向
	    request.getRequestDispatcher("DepEdit.jsp").forward(request,response);
	}

	/**
	 * @see HttpServlet#doPost(HttpServletRequest request, HttpServletResponse response)
	 */
	protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		// TODO Auto-generated method stub
		doGet(request, response);
	}

}
